<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>仓库管理</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/material/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/icon.css">
    <script type="text/javascript" src="/static/plugins/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script>
        $(function () {
            $('#depot_dg').datagrid({
                url: '/depot/selectAll.do',
                fitColumns: true,
                fit: true,
                pagination: true,
                singleSelect: true,
                toolbar: "#depot_tb",
                rownumbers: true,
                columns: [[
                    {field: 'id', title: 'ID', width: 100},
                    {field: 'name', title: '仓库名称', width: 100},
                    {field: 'sn', title: '仓库编号', width: 100},
                    {field: 'tel', title: '电话', width: 100},
                    {
                        field: 'status', title: '状态', width: 100, formatter: function (value, row, index) {
                            return value ? "正常" : "<span style='color: red'>停用</span>"
                        }
                    },
                    {field: 'currentdate', title: '添加时间', width: 100},
                    {field: 'location', title: '仓库地址', width: 100},
                    {field: 'remark', title: '备注', width: 100}
                ]],
                onClickRow:function (index,row) {
                    if (row.state) {
                        $("#btn_change").linkbutton({
                            "text":"停用",
                            iconCls:"icon-no"
                        })
                    }else {
                        $("#btn_change").linkbutton({
                            "text":"正常",
                            iconCls:"icon-ok"
                        })
                    }
                }
            });

            $("#depot-dialog").dialog({
                width:300,
                height:450,
                closed:true,
                onClose:function () {
                    //清空表单数据
                    $("#depot-form").form("clear");
                }
            });
        })
        
        function reloadDepot() {
            $("#depot_dg").datagrid("reload");
        }

        function addDepot() {
            $("#depot-dialog").dialog("setTitle","员工新增");
            $("#depot-dialog").dialog("open");
        }

        function editDepot() {
            var currentRow = $("#depot_dg").datagrid("getSelected");
            if (!currentRow) {
                $.messager.alert("温馨提示","亲，请选择一条需要操作的数据","info");
                return;
            }
            $("#depot-dialog").dialog("setTitle","员工编辑");
            $("#depot-dialog").dialog("open");
            //数据回显
            $("#depot-form").form("load",currentRow);
        }
        
        function save() {
            $("#depot-form").form("submit",{
                url:"/depot/saveOrUpdate.do",
                success:function (data) {
                    data = $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert("温馨提示","保存成功","info",function () {
                            $("#depot-dialog").dialog("close");
                            $("#depot_dg").datagrid("reload");
                        })
                    }else {
                        $.messager.alert("温馨提示","保存失败","error");
                    }
                }
            })
        }
        
        function cancel () {
            $("#depot-dialog").dialog("close");
        }
    </script>
</head>
<body>
<table id="depot_dg"></table>
<div id="depot_tb">
    <a class="easyui-linkbutton" onclick="addDepot()" data-options="iconCls:'icon-add',text:'新增'"></a>
    <a class="easyui-linkbutton" onclick="editDepot()" data-options="iconCls:'icon-edit',text:'编辑'"></a>
    <a class="easyui-linkbutton" onclick="reloadDepot()" data-options="iconCls:'icon-reload',text:'刷新'"></a>
</div>
<div id="depot-dialog">
    <form id="depot-form" method="post">
        <input type="hidden" name="id" id="depot_id">
        <div style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="name" style="width: 100%" data-options="label:'仓库名称',labelWidth:60">
        </div>
        <div style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="sn" style="width: 100%" data-options="label:'仓库编码',labelWidth:60">
        </div>
        <div id="passwordDiv" style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="tel" style="width: 100%" data-options="label:'联系电话',labelWidth:60">
        </div>
        <div style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="location" style="width: 100%" data-options="label:'仓库地址',labelWidth:60">
        </div>
        <div style="margin-bottom: 20px;">
            <input class="easyui-textbox" name="remark" style="width: 100%" data-options="label:'仓库备注',labelWidth:60,">
        </div>
        <a class="easyui-linkbutton" onClick="save()" data-options="iconCls:'icon-save',plain:true">保存</a>
        <a class="easyui-linkbutton" onclick="cancel()" data-options="iconCls:'icon-cancel',plain:true">取消</a>
    </form>
</div>
</body>
</html>
